package offer;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Ex38 {
    Set<String> set;
    int len;
    List<String> res;
    StringBuffer str = new StringBuffer();

    public String[] permutation(String s) {
        set = new HashSet<String>();
        len = s.length();
        res = new ArrayList<String>();
        dfs(s,0);

        return (String[])res.toArray(new String[res.size()]);

    }
    public void dfs(String s,int p){
        if(s.length()==p){
            if(set.add(new String(str))){
                res.add(new String(str));
            }
        }
        for(int i = 0;i<s.length();i++ ){

            str.append(s.charAt(i));
            dfs(s,p+1);
            str.deleteCharAt(str.length()-1);

        }
    }

    public static void main(String[] args) {
        Ex38 ex38 = new Ex38();
        ex38.permutation("abc");
    }
}
